package trb.complexshield.voxel;

import java.util.BitSet;

public class VoxelGrid {
    public final int xdim;
    public final int ydim;
    public final int zdim;
    public final BitSet bitSet;

    public VoxelGrid(int xdim, int ydim, int zdim) {
        this.xdim = xdim;
        this.ydim = ydim;
        this.zdim = zdim;
        bitSet = new BitSet(xdim * ydim * zdim);
    }

    public void setBitAtIndex(int xIdx, int yIdx, int zIdx, boolean value) {
        bitSet.set((zIdx * xdim * ydim + yIdx * xdim + xIdx), value);
    }

    public boolean getBitAtIndex(int xIdx, int yIdx, int zIdx) {
        if (xIdx < 0 || xIdx >= xdim || yIdx < 0 || yIdx >= ydim || zIdx < 0 || zIdx >= zdim) {
            return false;
        }
        return bitSet.get((zIdx * xdim * ydim + yIdx * xdim + xIdx));
    }
}
